package com.stn.zjx.givingtreasure.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;


import com.orhanobut.logger.Logger;
import com.stn.zjx.givingtreasure.greendao.DaoMaster;
import com.stn.zjx.givingtreasure.greendao.TestDao;
import com.stn.zjx.givingtreasure.table.Test;

import org.greenrobot.greendao.database.Database;

/**
 * Created by Simon on 12/8/2017.
 */

public class MySQLiteOpenHelper extends DaoMaster.OpenHelper {

    public MySQLiteOpenHelper(Context context, String name) {
        super(context, name);
        Log.i("greenDAO","MyOpenHelper");
    }

    public MySQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory) {
        super(context, name, factory);
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //MigrationHelper.migrate(db,UserKeyBeanDao.class);

        Log.i("greenDAO","当前数据库版本oldVersion"+oldVersion);
        if (newVersion > oldVersion) {
            MigrationHelper.migrate(db, new MigrationHelper.ReCreateAllTableListener() {
                @Override
                public void onCreateAllTables(Database db, boolean ifNotExists) {
                    DaoMaster.createAllTables(db, ifNotExists);
                }

                @Override
                public void onDropAllTables(Database db, boolean ifExists) {
                    DaoMaster.dropAllTables(db, ifExists);
                }
            }, TestDao.class);

        }
    }
}
